home *** CD-ROM | disk | FTP | other *** search
- #include <math.h>
- #include <dinput.h>
-
- #include "tankwars.h"
-
- void createbigexplosion(int xpos, int ypos);
-
- // Direct Input
- extern LPDIRECTINPUT7 g_DI;
- // Keyboard Device
- extern LPDIRECTINPUTDEVICE7 g_KDIDev;
-
- extern BYTE key[256];
- extern bool mousebutton[2];
-
- int grid[30][20];
- float cameraangle;
- float fps;
-
- c_player player[2];
-
- c_explosion explosion[50];
- int nextexplosionslot;
-
- c_missle missle[20];
- int nextmissleslot;
-
- c_smoke smoke[50];
- int nextsmokeslot;
-
- c_grenade grenade[20];
- int nextgrenadeslot;
-
- c_particle particle[500];
- int nextparticleslot;
-
- c_debris debris[100];
- int nextdebrisslot;
-
- unsigned long wall;
-
- int poweruptime;
-
- int winner;
-
- int fogenabled;
- int timeofday;
- int raindensity;
-
- void maingame(void)
- {
- MSG msg; // Windows Message Structure
- BOOL finished=FALSE; // Bool Variable To Exit Loop
-
- int i, i2, x, y;
-
- _2Df futurepos;
-
- // The position of the mouse:
- POINT mousepos;
-
- // Variables to aid in calculation of Frames per second:
- _int64 t, m, clckpersec;
-
- // Calculates how many clock ticks per second:
- QueryPerformanceFrequency((LARGE_INTEGER*)&clckpersec);
-
- // Frame limiter:
- int framelimit=1;
-
- while(!finished) // Loop That Runs While done=FALSE
- {
- if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
- {
- if (msg.message==WM_QUIT) // Have We Received A Quit Message?
- finished=TRUE; // If So done=TRUE
- else // If Not, Deal With Window Messages
- {
- TranslateMessage(&msg); // Translate The Message
- DispatchMessage(&msg); // Dispatch The Message
- }
- }
- else // If There Are No Messages
- {
- QueryPerformanceCounter((LARGE_INTEGER*)&t);
- HRESULT hr = g_KDIDev->GetDeviceState(sizeof(key), &key); // Get The Keys That Have Been Pressed ( Add )
- // BEGINNING OF MAIN LOOP
-
- for(i=0; i<2; i++)
- {
- if(key[player[i].control.right] & 0x80)
- {
- player[i].rot+=15;
- if(player[i].rot>=360)
- player[i].rot=player[i].rot-360;
- }
- if(key[player[i].control.left] & 0x80)
- {
- player[i].rot-=15;
- if(player[i].rot<0)
- player[i].rot=360+player[i].rot;
- }
- if(key[player[i].control.forward] || key[player[i].control.backward] & 0x80)
- {
- if(key[player[i].control.forward] & 0x80)
- {
- futurepos.x=player[i].pos.x+(float)cos(player[i].rot*PI/180)*2;
- futurepos.y=player[i].pos.y+(float)sin(player[i].rot*PI/180)*2;
- }
- if(key[player[i].control.backward] & 0x80)
- {
- futurepos.x=player[i].pos.x-(float)cos(player[i].rot*PI/180)*2;
- futurepos.y=player[i].pos.y-(float)sin(player[i].rot*PI/180)*2;
- }
-
-
- if(grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==BRICK1 || grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==BRICK0 || grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==TREE || grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==TRUNK || grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==i+BLUEGATE)
- {
- if(futurepos.x-3<((int)player[i].pos.x/(int)10-(int)1)*(int)10+(int)10)
- futurepos.x=(float)(((int)(player[i].pos.x/10)-1)*10+10+3);
- }
- if(grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==BRICK1 || grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==BRICK0 || grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==TREE || grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==TRUNK || grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==i+BLUEGATE)
- {
- if(futurepos.x+3>((int)player[i].pos.x/(int)10+(int)1)*(int)10)
- futurepos.x=(float)(((int)(player[i].pos.x/10)+1)*10-3);
- }
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==BRICK1 || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==BRICK0 || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==TREE || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==TRUNK || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==i+BLUEGATE)
- {
- if(futurepos.y-3<((int)player[i].pos.y/(int)10-(int)1)*(int)10+(int)10)
- futurepos.y=(float)(((int)(player[i].pos.y/10)-1)*10+10+3);
- }
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==BRICK1 || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==BRICK0 || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==TREE || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==TRUNK || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==i+BLUEGATE)
- {
- if(futurepos.y+3>((int)player[i].pos.y/(int)10+(int)1)*(int)10)
- futurepos.y=(float)(((int)(player[i].pos.y/10)+1)*10-3);
- }
-
- if(grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==BRICK1 || grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==BRICK0 || grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==TREE || grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==TRUNK || grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==i+BLUEGATE)
- {
- futurepos.x=player[i].pos.x;
- futurepos.y=player[i].pos.y;
- }
-
-
- if(futurepos.x-3<0)
- futurepos.x=3;
- if(futurepos.x+3>300)
- futurepos.x=297;
- if(futurepos.y-3<0)
- futurepos.y=3;
- if(futurepos.y+3>200)
- futurepos.y=197;
-
- if(wall>0)
- {
- if(i==0)
- if(futurepos.x+3>150)
- futurepos.x=147;
- if(i==1)
- if(futurepos.x-3<150)
- futurepos.x=153;
- }
-
- player[i].pos.x=futurepos.x;
- player[i].pos.y=futurepos.y;
- }
-
- // Calculate player's new build position:
- player[i].buildpos.x=(int)((float)(player[i].pos.x+cos(player[i].rot*PI/180)*10)/(float)10);
- player[i].buildpos.y=(int)((float)(player[i].pos.y+sin(player[i].rot*PI/180)*10)/(float)10);
-
- // Check if player switches mode:
- if(key[player[i].control.rightchange] & 0x80 && !player[i].control.rightf)
- {
- player[i].control.rightf=1;
- player[i].mode++;
- if(player[i].mode>3)
- player[i].mode=0;
- }
- if(!(key[player[i].control.rightchange] & 0x80))
- player[i].control.rightf=0;
-
- if((key[player[i].control.leftchange] & 0x80) && (!player[i].control.leftf))
- {
- player[i].control.leftf=1;
- player[i].mode--;
- if(player[i].mode<0)
- player[i].mode=3;
- }
- if(!(key[player[i].control.leftchange] & 0x80))
- player[i].control.leftf=0;
-
- // Check if player wants to build a Brick
- if(key[player[i].control.fire] & 0x80 && player[i].mode==BRICK_MODE && player[i].ammo.bricks>0 && player[i].rebirth==0)
- {
- if(grid[player[i].buildpos.x][player[i].buildpos.y]==EMPTY && player[i].buildpos.x>=0 && player[i].buildpos.x<30 && player[i].buildpos.y>=0 && player[i].buildpos.y<20)
- {
- grid[player[i].buildpos.x][player[i].buildpos.y]=BRICK1;
- player[i].ammo.bricks--;
- if(player[i].pos.x-3<player[i].buildpos.x*10+10 &&
- player[i].pos.x+3>player[i].buildpos.x*10 &&
- player[i].pos.y-3<player[i].buildpos.y*10+10 &&
- player[i].pos.y+3>player[i].buildpos.y*10)
- {
- player[i].pos.x-=(float)cos(player[i].rot*PI/180)*4;
- player[i].pos.y-=(float)sin(player[i].rot*PI/180)*4;
- }
- }
- }
- // Check if player wants to build a Mine
- if(key[player[i].control.fire] & 0x80 && player[i].mode==MINE_MODE && player[i].ammo.mines>0 && player[i].rebirth==0)
- {
- if(grid[player[i].buildpos.x][player[i].buildpos.y]==EMPTY && player[i].buildpos.x>=0 && player[i].buildpos.x<30 && player[i].buildpos.y>=0 && player[i].buildpos.y<20)
- {
- grid[player[i].buildpos.x][player[i].buildpos.y]=MINE;
- player[i].ammo.mines--;
- if(player[i].pos.x-3<player[i].buildpos.x*10+10 &&
- player[i].pos.x+3>player[i].buildpos.x*10 &&
- player[i].pos.y-3<player[i].buildpos.y*10+10 &&
- player[i].pos.y+3>player[i].buildpos.y*10)
- {
- player[i].pos.x-=(float)cos(player[i].rot*PI/180)*4;
- player[i].pos.y-=(float)sin(player[i].rot*PI/180)*4;
- }
- }
- }
-
- // Check if player wants to fire a missle:
- if(key[player[i].control.fire] & 0x80 && player[i].mode==MISSLE_MODE && player[i].ammo.missles>0 && player[i].missleload==0 && player[i].rebirth==0)
- {
- PlaySound("Data/Missle.wav", NULL, SND_ASYNC);
- player[i].ammo.missles--;
- player[i].missleload=20;
- missle[nextmissleslot].active=1;
- missle[nextmissleslot].rot=player[i].rot;
- missle[nextmissleslot].pos.x=player[i].pos.x+(float)cos(player[i].rot*PI/180)*4;
- missle[nextmissleslot].pos.y=player[i].pos.y+(float)sin(player[i].rot*PI/180)*4;
- missle[nextmissleslot].start.x=(int)(player[i].pos.x/10);
- missle[nextmissleslot].start.y=(int)(player[i].pos.y/10);
- missle[nextmissleslot].smoke=nextsmokeslot;
-
- smoke[nextsmokeslot].rot=player[i].rot;
- smoke[nextsmokeslot].pos.x=player[i].pos.x+(float)cos(player[i].rot*PI/180)*4;
- smoke[nextsmokeslot].pos.y=player[i].pos.y+(float)sin(player[i].rot*PI/180)*4;
- smoke[nextsmokeslot].active=1;
- smoke[nextsmokeslot].life=0;
- smoke[nextsmokeslot].length=0;
- smoke[nextsmokeslot].stillmoving=1;
-
- nextmissleslot=0;
- while(missle[nextmissleslot].active)
- nextmissleslot++;
-
- nextsmokeslot=0;
- while(smoke[nextsmokeslot].active)
- nextsmokeslot++;
- }
-
- // Check if player wants to fire a grenade:
- if(key[player[i].control.fire] & 0x80 && player[i].mode==GRENADE_MODE && player[i].ammo.grenades>0 && player[i].grenadeload==0 && player[i].rebirth==0)
- {
- if(grid[player[i].buildpos.x][player[i].buildpos.y]==EMPTY && player[i].buildpos.x>=0 && player[i].buildpos.x<30 && player[i].buildpos.y>=0 && player[i].buildpos.y<20)
- {
- PlaySound("Data/Gren_tick.wav", NULL, SND_ASYNC);
- player[i].ammo.grenades--;
- player[i].grenadeload=50;
- grenade[nextgrenadeslot].stage=25;
- grenade[nextgrenadeslot].pos.x=player[i].buildpos.x;
- grenade[nextgrenadeslot].pos.y=player[i].buildpos.y;
- nextgrenadeslot=0;
- while(grenade[nextgrenadeslot].stage>0)
- nextgrenadeslot++;
- }
- }
-
-
- // Check if player crashed into a Mine:
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==MINE)
- {
- if(sqrt((player[i].pos.x-((int)(player[i].pos.x/10)*10+5))*(player[i].pos.x-((int)(player[i].pos.x/10)*10+5))+(player[i].pos.y-(int)((player[i].pos.y/10)*10+5))+(player[i].pos.y-(int)((player[i].pos.y/10)*10+5)))<5)
- {
- grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
-
- explosion[nextexplosionslot].stage=19;
- explosion[nextexplosionslot].pos.x=(int)(player[i].pos.x/10);
- explosion[nextexplosionslot].pos.y=(int)(player[i].pos.y/10);
- nextexplosionslot=0;
- while(explosion[nextexplosionslot].stage>0)
- {
- nextexplosionslot++;
- if(nextexplosionslot==50)
- {
- nextexplosionslot=0;
- explosion[0].stage=0;
- }
- }
- for(i2=0; i2<5; i2++)
- {
- debris[nextdebrisslot].active=1;
- debris[nextdebrisslot].pos.x=(float)((int)(player[i].pos.x/10)*10+5);
- debris[nextdebrisslot].pos.y=(float)((int)(player[i].pos.y/10)*10+5);
- debris[nextdebrisslot].pos.z=0.0f;
- debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
- if(i==0)
- {
- debris[nextdebrisslot].color.x=0.6f;
- debris[nextdebrisslot].color.y=0.1f;
- debris[nextdebrisslot].color.z=0.0f;
- }
- if(i==1)
- {
- debris[nextdebrisslot].color.x=0.0f;
- debris[nextdebrisslot].color.y=0.1f;
- debris[nextdebrisslot].color.z=0.6f;
- }
-
- nextdebrisslot=0;
- while(debris[nextdebrisslot].active==1)
- {
- nextdebrisslot++;
- if(nextdebrisslot==500)
- {
- nextdebrisslot=0;
- debris[0].active=0;
- }
- }
- }
- for(i2=0; i2<100; i2++)
- {
- particle[nextparticleslot].life=1;
- particle[nextparticleslot].pos.x=(float)((int)(player[i].pos.x/10)*10+5);
- particle[nextparticleslot].pos.y=(float)((int)(player[i].pos.y/10)*10+5);
- particle[nextparticleslot].pos.z=0.0f;
- particle[nextparticleslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- particle[nextparticleslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- particle[nextparticleslot].dir.z=(float)(rand()%200)/(float)100;
- nextparticleslot=0;
- while(particle[nextparticleslot].life>0)
- {
- nextparticleslot++;
- if(nextparticleslot==500)
- {
- nextparticleslot=0;
- particle[0].life=0;
- }
- }
- }
-
- PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
- player[i].rebirth=100;
- player[i].lives--;
- player[i].pos.x=(float)(player[i].startpos.x*10+5);
- player[i].pos.y=(float)(player[i].startpos.y*10+5);
- if(i==0)
- player[i].rot=0;
- if(i==1)
- player[i].rot=180;
- }
- }
-
- // Check if player got a power up:
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==LIFE_POWERUP)
- {
- player[i].lives++;
- grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
- }
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==BRICK_POWERUP)
- {
- player[i].ammo.bricks+=10;
- grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
- }
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==MINE_POWERUP)
- {
- player[i].ammo.mines+=10;
- grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
- }
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==MISSLE_POWERUP)
- {
- player[i].ammo.missles+=10;
- grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
- }
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==GRENADE_POWERUP)
- {
- player[i].ammo.grenades+=5;
- grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
- }
-
- // Check if player got the enemys flag:
- if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==i+BLUEFLAG)
- {
- if(sqrt((player[i].pos.x-((int)(player[i].pos.x/10)*10+5))*(player[i].pos.x-((int)(player[i].pos.x/10)*10+5))+(player[i].pos.y-(int)((player[i].pos.y/10)*10+5))+(player[i].pos.y-(int)((player[i].pos.y/10)*10+5)))<5)
- {
- PlaySound("Data/Flag_Cap.wav", NULL, SND_SYNC);
- winner=i;
- finished=TRUE;
- }
- }
-
- // Reload player's missles and grenades
- if(player[i].missleload>0)
- player[i].missleload--;
- if(player[i].grenadeload>0)
- player[i].grenadeload--;
-
- // Check player rebirth:
- if(player[i].rebirth>0)
- {
- player[i].rebirth--;
- player[i].pos.x=(float)(player[i].startpos.x*10+5);
- player[i].pos.y=(float)(player[i].startpos.y*10+5);
- if(i==0)
- player[i].rot=0;
- if(i==1)
- player[i].rot=180;
- }
- }
-
- // Add a powerup
- poweruptime--;
- if(poweruptime==0)
- {
- poweruptime=125;
- x=rand()%30;
- y=rand()%20;
- i=0;
- while(grid[x][y]!=EMPTY && i<600)
- {
- x=rand()%30;
- y=rand()%20;
- i++;
- }
- i=rand()%5+10;
- grid[x][y]=i;
- }
-
- // Check if both Tanks crashed into each other:
- if(sqrt((player[0].pos.x-player[1].pos.x)*(player[0].pos.x-player[1].pos.x)+(player[0].pos.y-player[1].pos.y)*(player[0].pos.y-player[1].pos.y))<=6)
- {
- explosion[nextexplosionslot].stage=19;
- explosion[nextexplosionslot].pos.x=(int)((player[0].pos.x+player[1].pos.x)/2/10);
- explosion[nextexplosionslot].pos.y=(int)((player[0].pos.y+player[1].pos.y)/2/10);
- nextexplosionslot=0;
- while(explosion[nextexplosionslot].stage>0)
- {
- nextexplosionslot++;
- if(nextexplosionslot==50)
- {
- nextexplosionslot=0;
- explosion[0].stage=0;
- }
- }
- for(i2=0; i2<10; i2++)
- {
- debris[nextdebrisslot].active=1;
- debris[nextdebrisslot].pos.x=(float)((int)((player[0].pos.x+player[1].pos.x)/2/10)*10+5);
- debris[nextdebrisslot].pos.y=(float)((int)((player[0].pos.y+player[1].pos.y)/2/10)*10+5);
- debris[nextdebrisslot].pos.z=0.0f;
- debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
- if(i2<5)
- {
- debris[nextdebrisslot].color.x=0.6f;
- debris[nextdebrisslot].color.y=0.1f;
- debris[nextdebrisslot].color.z=0.0f;
- }
- else
- {
- debris[nextdebrisslot].color.x=0.0f;
- debris[nextdebrisslot].color.y=0.1f;
- debris[nextdebrisslot].color.z=0.6f;
- }
-
- nextdebrisslot=0;
- while(debris[nextdebrisslot].active==1)
- {
- nextdebrisslot++;
- if(nextdebrisslot==500)
- {
- nextdebrisslot=0;
- debris[0].active=0;
- }
- }
- }
- for(i2=0; i2<100; i2++)
- {
- particle[nextparticleslot].life=1;
- particle[nextparticleslot].pos.x=(float)((int)((player[0].pos.x+player[1].pos.x)/2/10)*10+5);
- particle[nextparticleslot].pos.y=(float)((int)((player[0].pos.y+player[1].pos.y)/2/10)*10+5);
- particle[nextparticleslot].pos.z=0.0f;
- particle[nextparticleslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- particle[nextparticleslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- particle[nextparticleslot].dir.z=(float)(rand()%200)/(float)100;
- nextparticleslot=0;
- while(particle[nextparticleslot].life>0)
- {
- nextparticleslot++;
- if(nextparticleslot==500)
- {
- nextparticleslot=0;
- particle[0].life=0;
- }
- }
- }
-
- PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
- player[0].rebirth=100;
- player[1].rebirth=100;
- player[0].lives--;
- player[1].lives--;
-
- player[0].pos.x=(float)(player[0].startpos.x*10+5);
- player[0].pos.y=(float)(player[0].startpos.y*10+5);
- player[0].rot=0;
- player[1].pos.x=(float)(player[1].startpos.x*10+5);
- player[1].pos.y=(float)(player[1].startpos.y*10+5);
- player[1].rot=180;
- }
-
- // Lower the wall:
- if(wall>0)
- wall--;
-
- // Move all the missles:
- for(i=0; i<20; i++)
- {
- if(missle[i].active)
- {
- missle[i].pos.x+=(float)cos(missle[i].rot*PI/180)*4;
- missle[i].pos.y+=(float)sin(missle[i].rot*PI/180)*4;
-
- for(i2=0; i2<2; i2++)
- {
- if(sqrt((missle[i].pos.x-player[i2].pos.x)*(missle[i].pos.x-player[i2].pos.x)+(missle[i].pos.y-player[i2].pos.y)*(missle[i].pos.y-player[i2].pos.y))<6 && player[i2].rebirth==0)
- {
- explosion[nextexplosionslot].stage=19;
- explosion[nextexplosionslot].pos.x=(int)(player[i2].pos.x/10);
- explosion[nextexplosionslot].pos.y=(int)(player[i2].pos.y/10);
- nextexplosionslot=0;
- while(explosion[nextexplosionslot].stage>0)
- {
- nextexplosionslot++;
- if(nextexplosionslot==50)
- {
- nextexplosionslot=0;
- explosion[0].stage=0;
- }
- }
- for(x=0; x<5; x++)
- {
- debris[nextdebrisslot].active=1;
- debris[nextdebrisslot].pos.x=(float)((int)(player[i2].pos.x/10)*10+5);
- debris[nextdebrisslot].pos.y=(float)((int)(player[i2].pos.y/10)*10+5);
- debris[nextdebrisslot].pos.z=0.0f;
- debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
- if(i2==0)
- {
- debris[nextdebrisslot].color.x=0.6f;
- debris[nextdebrisslot].color.y=0.1f;
- debris[nextdebrisslot].color.z=0.0f;
- }
- if(i2==1)
- {
- debris[nextdebrisslot].color.x=0.0f;
- debris[nextdebrisslot].color.y=0.1f;
- debris[nextdebrisslot].color.z=0.6f;
- }
-
- nextdebrisslot=0;
- while(debris[nextdebrisslot].active==1)
- {
- nextdebrisslot++;
- if(nextdebrisslot==500)
- {
- nextdebrisslot=0;
- debris[0].active=0;
- }
- }
- }
- for(x=0; x<100; x++)
- {
- particle[nextparticleslot].life=1;
- particle[nextparticleslot].pos.x=(float)((int)(player[i2].pos.x/10)*10+5);
- particle[nextparticleslot].pos.y=(float)((int)(player[i2].pos.y/10)*10+5);
- particle[nextparticleslot].pos.z=0.0f;
- particle[nextparticleslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- particle[nextparticleslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- particle[nextparticleslot].dir.z=(float)(rand()%200)/(float)100;
- nextparticleslot=0;
- while(particle[nextparticleslot].life>0)
- {
- nextparticleslot++;
- if(nextparticleslot==500)
- {
- nextparticleslot=0;
- particle[0].life=0;
- }
- }
- }
- missle[i].active=0;
- smoke[missle[i].smoke].stillmoving=0;
- if(i<nextmissleslot)
- nextmissleslot=0;
- PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
- player[i2].rebirth=100;
- player[i2].lives--;
- player[i2].pos.x=(float)(player[i2].startpos.x*10+5);
- player[i2].pos.y=(float)(player[i2].startpos.y*10+5);
- if(i2==0)
- player[i2].rot=0;
- if(i2==1)
- player[i2].rot=180;
- }
- }
-
- for(y=-1; y<2; y++)
- {
- for(x=-1; x<2; x++)
- {
- if((int)(missle[i].pos.x/10)+x>=0 && (int)(missle[i].pos.x/10)+x<30 && (int)(missle[i].pos.y/10)+y>=0 && (int)(missle[i].pos.y/10)+y<20)
- {
- if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=EMPTY && grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=MINE && grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=REDFLAG && grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=BLUEFLAG && grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=TRUNK)
- {
- if(missle[i].pos.x-3<(int)(missle[i].pos.x/10+x)*10+10 &&
- missle[i].pos.x+3>(int)(missle[i].pos.x/10+x)*10 &&
- missle[i].pos.y-3<(int)(missle[i].pos.y/10+y)*10+10 &&
- missle[i].pos.y+3>(int)(missle[i].pos.y/10+y)*10)
- {
- i2=0;
- if((int)(missle[i].pos.x/10)+x>=missle[i].start.x-1 && (int)(missle[i].pos.x/10)+x<=missle[i].start.x+1 && (int)(missle[i].pos.y/10)+y>=missle[i].start.y-1 && (int)(missle[i].pos.y/10)+y<=missle[i].start.y+1 && (grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK1 || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK0))
- i2=1;
- if(i2==0)
- {
- PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
- if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK1)
- grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=BRICK0;
- else if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK0)
- grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=EMPTY;
- else if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==TREE)
- grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=TRUNK;
- else if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==TREE)
- grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=TRUNK;
- else if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==LIFE_POWERUP || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK_POWERUP || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==MINE_POWERUP || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==MISSLE_POWERUP || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==GRENADE_POWERUP)
- {
- grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=EMPTY;
- createbigexplosion((int)(missle[i].pos.x/10)+x, (int)(missle[i].pos.y/10)+y);
- }
- explosion[nextexplosionslot].stage=19;
- explosion[nextexplosionslot].pos.x=(int)(missle[i].pos.x/10)+x;
- explosion[nextexplosionslot].pos.y=(int)(missle[i].pos.y/10)+y;
- nextexplosionslot=0;
- while(explosion[nextexplosionslot].stage>0)
- {
- nextexplosionslot++;
- if(nextexplosionslot==50)
- {
- nextexplosionslot=0;
- explosion[0].stage=0;
- }
- }
- for(i2=0; i2<100; i2++)
- {
- particle[nextparticleslot].life=1;
- particle[nextparticleslot].pos.x=(float)(((int)(missle[i].pos.x/10)+x)*10+5);
- particle[nextparticleslot].pos.y=(float)(((int)(missle[i].pos.y/10)+y)*10+5);
- particle[nextparticleslot].pos.z=0.0f;
- particle[nextparticleslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- particle[nextparticleslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- particle[nextparticleslot].dir.z=(float)(rand()%100)/(float)100;
- nextparticleslot=0;
- while(particle[nextparticleslot].life>0)
- {
- nextparticleslot++;
- if(nextparticleslot==500)
- {
- nextparticleslot=0;
- particle[0].life=0;
- }
- }
- }
- missle[i].active=0;
- smoke[missle[i].smoke].stillmoving=0;
- if(i<nextmissleslot)
- nextmissleslot=0;
- x=2;
- y=2;
- }
- }
- }
- }
- }
- }
-
- if(missle[i].pos.x-3<0 || missle[i].pos.x+3>300 || missle[i].pos.y-3<0 || missle[i].pos.y+3>200)
- {
- missle[i].active=0;
- smoke[missle[i].smoke].stillmoving=0;
- if(i<nextmissleslot)
- nextmissleslot=0;
- }
-
- // Check if missle hit the wall
- if(wall>0 && missle[i].pos.x+3>150-3 && missle[i].pos.x-3<150+3)
- {
- missle[i].active=0;
- smoke[missle[i].smoke].stillmoving=0;
- if(i<nextmissleslot)
- nextmissleslot=0;
- }
- }
- }
-
- GetCursorPos(&mousepos);
- // SetCursorPos(screen_w/2,screen_h/2);
- SetCursorPos(160, 120);
- if(mousebutton[0])
- {
- // if(cameraangle + (mousepos.y - screen_h/2 )/10 < 0)
- if(cameraangle + (mousepos.y - 160)/10 < 0)
- cameraangle=0;
- // else if(cameraangle + (mousepos.y - screen_h/2)/10 > 50)
- else if(cameraangle + (mousepos.y - 120)/10 > 50)
- cameraangle=50;
- else
- // cameraangle += (float)((float)mousepos.y - (float)screen_h/(float)2)/(float)10;
- cameraangle += (float)((float)mousepos.y - (float)120)/(float)10;
- }
-
- if (!DrawGLScene())
- finished=TRUE;
- if (key[DIK_ESCAPE] & 0x80)
- finished=TRUE;
- if(key[VK_SPACE] & 0x80)
- {
- framelimit=!framelimit;
- }
- if(key[DIK_1] & 0x80)
- {
- fogenabled=!fogenabled;
- }
- if(key[DIK_2] & 0x80)
- {
- timeofday=!timeofday;
- }
- if(key[DIK_3] & 0x80)
- {
- if(raindensity>0)
- raindensity=0;
- else
- raindensity=100;
- }
-
-
- // END OF MAIN LOOP
- QueryPerformanceCounter((LARGE_INTEGER*)&m);
- fps=(float)1/(float)((float)m/(float)clckpersec-(float)t/(float)clckpersec);
- if(framelimit)
- {
- while(fps>25)
- {
- QueryPerformanceCounter((LARGE_INTEGER*)&m);
- fps=(float)1/(float)((float)m/(float)clckpersec-(float)t/(float)clckpersec);
- }
- }
- }
- }
- }
-
- void createbigexplosion(int xpos, int ypos)
- {
- int i, x, y;
- PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
- if(player[0].pos.x+3>xpos*10-10 &&
- player[0].pos.x-3<xpos*10+20 &&
- player[0].pos.y+3>ypos*10-10 &&
- player[0].pos.y-3<ypos*10+20 &&
- player[0].rebirth==0)
- {
- for(x=0; x<7; x++)
- {
- debris[nextdebrisslot].active=1;
- debris[nextdebrisslot].pos.x=(float)((int)(player[0].pos.x/10)*10+5);
- debris[nextdebrisslot].pos.y=(float)((int)(player[0].pos.y/10)*10+5);
- debris[nextdebrisslot].pos.z=0.0f;
- debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
- debris[nextdebrisslot].color.x=0.6f;
- debris[nextdebrisslot].color.y=0.1f;
- debris[nextdebrisslot].color.z=0.0f;
- while(debris[nextdebrisslot].active==1)
- {
- nextdebrisslot++;
- if(nextdebrisslot==500)
- {
- nextdebrisslot=0;
- debris[0].active=0;
- }
- }
- }
- player[0].rebirth=100;
- player[0].lives--;
- player[0].pos.x=(float)(player[0].startpos.x*10+5);
- player[0].pos.y=(float)(player[0].startpos.y*10+5);
- player[0].rot=0;
- }
- if(player[1].pos.x+3>xpos*10-10 &&
- player[1].pos.x-3<xpos*10+20 &&
- player[1].pos.y+3>ypos*10-10 &&
- player[1].pos.y-3<ypos*10+20 &&
- player[1].rebirth==0)
- {
- for(x=0; x<7; x++)
- {
- debris[nextdebrisslot].active=1;
- debris[nextdebrisslot].pos.x=(float)((int)(player[1].pos.x/10)*10+5);
- debris[nextdebrisslot].pos.y=(float)((int)(player[1].pos.y/10)*10+5);
- debris[nextdebrisslot].pos.z=0.0f;
- debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
- debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
- debris[nextdebrisslot].color.x=0.0f;
- debris[nextdebrisslot].color.y=0.1f;
- debris[nextdebrisslot].color.z=0.6f;
- nextdebrisslot=0;
- while(debris[nextdebrisslot].active==1)
- {
- nextdebrisslot++;
- if(nextdebrisslot==500)
- {
- nextdebrisslot=0;
- debris[0].active=0;
- }
- }
- }
- player[1].rebirth=100;
- player[1].lives--;
- player[1].pos.x=(float)(player[1].startpos.x*10+5);
- player[1].pos.y=(float)(player[1].startpos.y*10+5);
- player[1].rot=180;
- }
- for(i=0; i<200; i++)
- {
- particle[nextparticleslot].life=1;
- particle[nextparticleslot].pos.x=(float)(xpos*10+5);
- particle[nextparticleslot].pos.y=(float)(ypos*10+5);
- particle[nextparticleslot].pos.z=0.0f;
- particle[nextparticleslot].dir.x=(float)(rand()%200)/(float)100-(float)1;
- particle[nextparticleslot].dir.y=(float)(rand()%200)/(float)100-(float)1;
- particle[nextparticleslot].dir.z=(float)(rand()%200)/(float)100;
- nextparticleslot=0;
- while(particle[nextparticleslot].life>0)
- {
- nextparticleslot++;
- if(nextparticleslot==500)
- {
- nextparticleslot=0;
- particle[0].life=0;
- }
- }
- }
- for(y=-1; y<2; y++)
- {
- for(x=-1; x<2; x++)
- {
- if(xpos+x>=0 && xpos+x<30 && ypos+y>=0 && ypos+y<20)
- {
- explosion[nextexplosionslot].stage=19;
- explosion[nextexplosionslot].pos.x=xpos+x;
- explosion[nextexplosionslot].pos.y=ypos+y;
- nextexplosionslot=0;
- while(explosion[nextexplosionslot].stage>0)
- {
- nextexplosionslot++;
- if(nextexplosionslot==50)
- {
- nextexplosionslot=0;
- explosion[0].stage=0;
- }
- }
- if(grid[xpos+x][ypos+y]==BRICK1)
- grid[xpos+x][ypos+y]=BRICK0;
- else if(grid[xpos+x][ypos+y]==BRICK0)
- grid[xpos+x][ypos+y]=EMPTY;
- else if(grid[xpos+x][ypos+y]==TREE)
- grid[xpos+x][ypos+y]=TRUNK;
- else if(grid[xpos+x][ypos+y]==TRUNK)
- grid[xpos+x][ypos+y]=EMPTY;
- else if(grid[xpos+x][ypos+y]==MINE)
- grid[xpos+x][ypos+y]=EMPTY;
- else if(grid[xpos+x][ypos+y]==LIFE_POWERUP || grid[xpos+x][ypos+y]==BRICK_POWERUP || grid[xpos+x][ypos+y]==MINE_POWERUP || grid[xpos+x][ypos+y]==MISSLE_POWERUP || grid[xpos+x][ypos+y]==GRENADE_POWERUP)
- {
- grid[xpos+x][ypos+y]=EMPTY;
- createbigexplosion(xpos+x, ypos+y);
- }
- }
- }
- }
- }